# USAGE
# python index.py --dataset dataset --index index.csv

# import the necessary packages
from pyimagesearch.colordescriptor import ColorDescriptor
from elasticsearch import Elasticsearch
import argparse
import glob
import cv2

args = {}
args['index'] = 'index.csv'
args['dataset'] = 'D:/deep/data/dataset'

es = Elasticsearch(['192.168.1.199:9200'])

# initialize the color descriptor
cd = ColorDescriptor((8, 12, 3))

# use glob to grab the image paths and loop over them
for imagePath in glob.glob(args["dataset"] + "/*.png"):
	# extract the image ID (i.e. the unique filename) from the image
	# path and load the image itself
	imageID = imagePath[imagePath.rfind("/") + 1:]
	image = cv2.imread(imagePath)

	# describe the image
	features = cd.describe(image)

	# write the features to file
	features = [str(f) for f in features]
	#output.write("%s,%s\n" % (imageID, ",".join(features)))
	
	es.index(index="my_index2", doc_type="my_type", body={"img": imageID, "f": features})
	